<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>菜单添加</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport"
              content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <link rel="stylesheet" href="/components/layuiadmin/layui/src/css/layui.css">
        <script src="/components/layuiadmin/layui/src/layui.js"></script>
        <script src='/base/js/jquery-3.4.1.min.js'></script>
        <script src="/modules/js/app.js"></script>
    </head>
    <style>
        .layui-form-item .layui-input-inline {
            width: 360px;
        !important;
        }
    </style>
    <body>
        <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
             style="padding: 20px 30px 0 0;">

            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div id="urlShow" class="layui-form-item">
                <label class="layui-form-label">路由</label>
                <div class="layui-input-inline">
                    <input type="text" id="url" name="url" placeholder="请输入路由" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div id="urlShow2" class="layui-form-item">
                <label class="layui-form-label">第二路由</label>
                <div class="layui-input-inline">
                    <input type="text" id="twoUrl" name="twoUrl" placeholder="非必填" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="text" id="sort" name="sort" lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-inline">
                    <input type="text" id="icon" name="icon" lay-verify="required" placeholder="请选择图标" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
            </div>
        </div>
    </body>

    <script>

        layui.use(['form'], function () {
            init();
            formSubmit();
        });

        function init() {
            //默认值
            $("#sort").val(0);
            $("#icon").val("layui-icon-file-b");
            //判断
            if (parent.data.lv === 1) {
                // 添加系统--屏蔽路由
                $("#urlShow").attr("style", "display:none");
                $("#urlShow2").attr("style", "display:none");
            } else if (parent.data.lv === 2) {
                // 添加菜单--屏蔽路由
                $("#urlShow").attr("style", "display:none");
                $("#urlShow2").attr("style", "display:none");
            } else if (parent.data.lv === 3) {
                // 添加页面--路由必填
                $("#url").attr("lay-verify", "required");
            }
        }

        function formSubmit() {
            // 监听提交
            layui.form.on('submit(layuiadmin-app-form-submit)', function (data) {
                WindowPos.onbeforeunload();
                //顶级菜单父Id=0, 其他为当前选中行
                if (parent.data.lv === 1) {
                    data.field.pid = 0;
                } else {
                    data.field.pid = parent.data.id;
                }
                data.field.root = parent.data.lv;  // 目录级别
                let result = Ajax.post(path + "/admin/adminMenu/insert", data.field);
                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.layer.msg(result.msg);
                // 重载页面 // parent.window.location.reload();
                WindowPos.onbeforeunload();  // 记录滚动条位置
                parent.xijiaRenderTable();
                WindowPos.onload();          // 还原滚动条位置
            });
        }
    </script>
</html>